package ensemble;

import java.awt.Graphics;
import java.awt.image.*;
import java.io.*;


import javax.imageio.ImageIO;
public class LoadImage extends DataHandler{

	public static float [] loadData (BufferedImage bf) {
		Raster r = bf.getData();
		float [] data = new float [256];
		r.getPixels(0, 0, 16, 16, data);
		return data;
	} 
	

	public static BufferedImage loadImage (File image) throws IOException {
		BufferedImage bf = ImageIO.read(image);
		return bf;
	}

	public static BufferedImage reDraw (BufferedImage bf) {
		BufferedImage out = new BufferedImage (16, 16, BufferedImage.TYPE_BYTE_GRAY );
		Graphics g = out.createGraphics();
		g.drawImage(bf, 0, 0, 16, 16, 0, 0, bf.getHeight(), bf.getWidth(), null);
		return out;

	}

	public static void saveRedrawedImage (BufferedImage bf) throws IOException {
		File f = new File ("data/redrawed.png");
		ImageIO.write(bf, "png", f);
	}

	public static void main (String [] args) {
		try {
			BufferedImage in = loadImage(new File("data/totest.png"));
			BufferedImage out = reDraw (in);
			saveRedrawedImage(out);
			float [] data = loadData(out);
			for (int i = 0; i < data.length; i++) {
				System.out.print(data [i] + ",");
			}
		}catch(IOException e) {
			System.out.println(e);
		}
	}


	@Override
	public Object loadData(String file) throws IOException {
		// TODO Auto-generated method stub
		return null;
	}
}
